//加载公共样式
require('../../assets/css/index.less')

//加载自己的样式
require('./course-datail.less')
function $(arr) {
  return document.querySelector(arr)
}
//引入ajax工具函数
const request = require('../../utils/request')
require('../../assets/fonts/iconfont.css')

window.onload = () => {
  const courseId = location.search.split('=')[1]
  console.log('courseId', courseId)

  //获取数据
  function getData() {
    request
      .get('/api/train/courseDetail', {
        params: {
          id: courseId,
          
        },
      })
      .then(res => {
        console.log('res.data :>> ', res.data)
        //解构数据
        let {errno, data} = res.data
        //判断
        if (errno === 0) {
          //把训练数据存储到本地 给play页面用
          localStorage.setItem('fragments', JSON.stringify(data.fragments))
        }
      })
  }

  //初始化发请求
  getData()
  
}
$('.btn').addEventListener('click',function(){
  location.href='./play.html'
})